var vm = new Vue({
    el: '#rrapp',
    data: {
        q: {id: null, payNo: null, sellerId: null, applyStatusList: null},
        page: {currentPage: 0, pageSizes: [15, 30, 100], pageSize: 15, total: 0, ascending: [], descending: []},
        loading: false,
        sellerList: [],//工厂列表
        showList: true,
        title: null,
        applyCashFactoryData:[],// 工厂提现列表
        merchantApplyCash: {},
        merchantApplyCashItems: [],//提现明细
        merchantApplyLog:[], // 提现日志
        applyStatusList: [
            {value: '0', label: '待审核'}, {value: 1, label: '审核通过'},
            {value: 2, label: '已驳回'}, {value: 3,label: '打款成功'},
            {value: 4, label: '打款失败'}
        ],
        searchResultVisible: false,//查询结果弹窗
        searchResult:{},//查询结果
    },

    mounted: function () {
        this.query();
    },

    methods: {

        query: function () {
            //查询参数
            var queryParam = this.q;

            // 分页参数
            queryParam.page = this.page.currentPage;
            queryParam.limit = this.page.pageSize;
            // loading
           /* const loading = this.$loading({
                lock: true,
                text: '数据加载中',
                spinner: 'el-icon-loading'
            });*/
            //ajax 请求
            $.ajax({
                type: "POST",
                url: baseURL + "capital/merchantapplycash/factoryCheckList",
                contentType: "application/json;charset=UTF-8",
                data: JSON.stringify(queryParam),
                success: function (r) {
                    //loading.close();
                    if (r.code == 0) {
                        vm.page.total = r.page.totalCount;
                        vm.applyCashFactoryData = r.page.list;
                    } else {
                        alert(r.msg);
                    }
                }
            });

        },

        // 页数变化
        handleSizeChange: function (val) {
            this.page.pageSize = val;
            this.query();
        },
        //当前页变化
        handleCurrentChange: function (val) {
            this.page.currentPage = val;
            this.query();
        },

        goDetail: function (id) {
            vm.showList = false;
            vm.getApplyCashDetail(id);
        },

        rowClass:function (data) {
            if ((data.column.property === 'orderId' || data.column.property === 'orderCreateTime'
                    || data.column.property === 'paymentTime' || data.column.property === 'payed' || data.column.property === 'finishTime')
                && data.row.orderAccountId !== null){
                console.log(data.rowIndex)
                return 'warning-col';
            }
        },
        //远程模糊查找工厂
        remoteMethod: function (query) {
            if (query !== '') {
                vm.loading = true;
                //远程请求
                $.get(baseURL + "capital/merchantapplycash/getSellerInfo?sellerType=1&keyWord=" + query, function (r) {
                    vm.loading = false;
                    if (r.code == 0) {
                        vm.sellerList = r.sellerList;
                    } else {
                        alert(r.msg);
                    }
                });
            } else {
                vm.sellerList = [];
            }
        },
        //审核
        check: function () {
            if (!vm.merchantApplyCash.id) {
                alert("该单据id异常,请刷新重试!");
                return;
            }
            var self = this;
            this.$confirm('确定要审核该条记录吗, 是否继续?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                const loading = self.$loading({
                    lock: true,
                    text: '打款中,请勿刷新页面',
                    spinner: 'el-icon-loading'
                });
                $.ajax({
                    type: "POST",
                    url: baseURL + "capital/merchantapplycash/checkFactory",
                    contentType: "application/json",
                    data: JSON.stringify(vm.merchantApplyCash.id),
                    success: function (r) {
                        loading.close();
                        if (r.code == 0) {
                            alert(r.msg, function (index) {
                                vm.goDetail(vm.merchantApplyCash.id);
                            });
                        } else {
                            alert(r.msg);
                        }
                    }
                });
            }).catch(() => {
                //loading.close();
            });

        },
        //驳回
        reject: function (event) {

        },
        //返回
        goBack: function () {
            vm.showList = true;
            this.query();
        },
        // 跳转详情页
        getApplyCashDetail: function (id) {
            $.get(baseURL + "capital/merchantapplycash/info/" + id, function (r) {
                if (r.code == 0) {
                    vm.merchantApplyCash = r.merchantApplyCash;
                    vm.merchantApplyCashItems = r.merchantApplyCashItems;
                    vm.merchantApplyLog = r.merchantApplyLog;
                } else {
                    alert(r.msg);
                }
            });
        },

        // 调用联动api 查看订单状态
        search: function () {
            var searchParam ={};
            if(!this.merchantApplyCash.applyPayId){
                alert("当前订单未生成联动支付单号,暂不支持查询!");
                return;
            }
            searchParam.orderId = this.merchantApplyCash.applyPayId;
            searchParam.merDate =  this.merchantApplyCash.auditTime;
            $.ajax({
                type: "POST",
                url: baseURL + "capital/merchantapplycash/searchUmfOrderStatus",
                contentType: "application/json",
                data: JSON.stringify(searchParam),
                success: function (r) {
                    if (r.code == 0) {
                        vm.searchResultVisible = true;
                        vm.searchResult = r.data;
                    } else {
                        alert(r.msg);
                    }
                }
            });
        },
        //重置审核状态
        resetApplyStatus:function () {
            var self = this;
            this.$confirm('确认将订单状态置为待审核? 这将导致该订单可以再次被审核,打款!', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                // 业务
                const loading = self.$loading({
                    lock: true,
                    text: '重置审核状态中,请勿刷新页面',
                    spinner: 'el-icon-loading'
                });
                var searchParam ={};

                searchParam.id = vm.merchantApplyCash.id
                searchParam.orderId = vm.merchantApplyCash.applyPayId;
                searchParam.merDate =  vm.merchantApplyCash.applyTime;
                $.ajax({
                    type: "POST",
                    url: baseURL + "capital/merchantapplycash/resetApplyStatus",
                    contentType: "application/json",
                    data: JSON.stringify(searchParam),
                    success: function (r) {
                        loading.close();
                        if (r.code == 0) {
                            alert(r.msg, function (index) {
                                vm.goDetail(vm.merchantApplyCash.id);
                                vm.searchResultVisible = false;
                            });
                        } else {
                            alert(r.msg);
                        }
                    }
                });
            }).catch(() => {
                this.$message({
                    type: 'info',
                    message: '已取消确认打款'
                });
            });
        },
        //确认打款
        confirmCash: function () {
            var self = this;
            this.$confirm('确认客户已收到打款?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                // 业务
                const loading = self.$loading({
                    lock: true,
                    text: '确认打款中,请勿刷新页面',
                    spinner: 'el-icon-loading'
                });
                var searchParam ={};
                searchParam.id = vm.merchantApplyCash.id;
                searchParam.orderId = vm.merchantApplyCash.applyPayId;
                searchParam.merDate =  vm.merchantApplyCash.applyTime;
                $.ajax({
                    type: "POST",
                    url: baseURL + "capital/merchantapplycash/confirmCash",
                    contentType: "application/json",
                    data: JSON.stringify(searchParam),
                    success: function (r) {
                        loading.close();
                        if (r.code == 0) {
                            alert(r.msg, function (index) {
                                vm.goDetail(vm.merchantApplyCash.id);
                                vm.searchResultVisible = false;
                            });
                        } else {
                            alert(r.msg);
                        }
                    }
                });
            }).catch(() => {
                this.$message({
                    type: 'info',
                    message: '已取消确认打款'
                });
            });

        }
    },


});